const RouterHook = require("../module/routerModule")
const router = RouterHook()
const {
    addPlanList,
    updatePlanList,
    delPlanList,
    getPlanList
} = require('../service/adminMaintenancePlan')

/**
 * @swagger
 * /admin/maintenance/plan/getList:
 *   get:
 *     tags:
 *       - 管理后台维保
 *     summary: 获取维保列表
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: query
 *         in: query
 *         description: 维保类型名称、类目、价格、总价、周期，支持模糊查询
 *         required: false
 *         schema:
 *           type: string
 *     responses:
 *       '200':
 *         description: 返回维保列表
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 data:
 *                   type: array
 *                   items:
 *                     type: object
 *                     properties:
 *                       id:
 *                         type: integer
 *                       replacement_parts:
 *                         type: string
 *                       category:
 *                         type: string
 *                       price:
 *                         type: number
 *                       total_price:
 *                         type: number
 *                       date:
 *                         type: string
 *                         format: date-time
 *       '401':
 *         description: 参数错误
 */


router.get('/getList', async (ctx) => {
    const { replacement_parts, category, price, total_price, date } = ctx.query
    const result = await getPlanList(replacement_parts, category, price, total_price, date)
    return ctx.result.success(result)
})

/**
 * @swagger
 * /admin/maintenance/plan/getList:
 *   get:
 *     tags:
 *       - 管理后台维保
 *     summary: 获取维保列表
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: query
 *         in: query
 *         description: 维保类型名称、类目、价格、总价、周期，支持模糊查询
 *         required: false
 *         schema:
 *           type: string
 *     responses:
 *       '200':
 *         description: 返回维保列表
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 data:
 *                   type: array
 *                   items:
 *                     type: object
 *                     properties:
 *                       id:
 *                         type: integer
 *                       replacement_parts:
 *                         type: string
 *                       category:
 *                         type: string
 *                       price:
 *                         type: number
 *                       total_price:
 *                         type: number
 *                       date:
 *                         type: string
 *                         format: date-time
 *                         example: "2020-12-11T16:00:00.000Z"
 *       '401':
 *         description: 参数错误
 */


// 删除维保
router.post('/delete', async (ctx) => {
    const body = ctx.request.body
    const result = await delPlanList(body)
    return ctx.result.success(result)
})

/**
 * @swagger
 * /admin/maintenance/plan/add:
 *   post:
 *     tags:
 *       - 管理后台维保
 *     summary: 添加维保列表
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: id
 *         in: formData
 *         description: 维保id
 *         required: true
 *         schema:
 *           type: number
 *       - name: replacement_parts
 *         in: formData
 *         description: 更换零件
 *         required: true
 *         schema:
 *           type: string
 *       - name: category
 *         in: formData
 *         description: 维修类目
 *         required: true
 *         schema:
 *           type: string
 *       - name: price
 *         in: formData
 *         description: 单项价格
 *         required: true
 *         schema:
 *           type: number
 *       - name: total_price
 *         in: formData
 *         description: 维修总价
 *         required: true
 *         schema:
 *           type: number
 *       - name: date
 *         in: formData
 *         description: 维修周期
 *         required: true
 *         schema:
 *           type: string
 *           format: date
 *           example: "2022-01-17"
 *     responses:
 *       '200':
 *         description: 返回信息
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 data:
 *                   type: array
 *                   items:
 *                     type: object
 *                     properties:
 *                       message:
 *                         type: string
 *                         example: "添加成功"
 *       '401':
 *         description: 参数错误
 */

router.post('/add', async (ctx) => {
    const body = ctx.request.body
    const result = await addPlanList(body)
    return ctx.result.success(result)
})

/**
 * @swagger
 * /admin/maintenance/plan/update:
 *   post:
 *     tags:
 *       - 管理后台维保
 *     summary: 修改维保列表
 *     produces:
 *       - application/json
 *     parameters:
 *       - name: replacement_parts
 *         description: 更换零件
 *         required: true
 *         type: string
 *       - name: category
 *         description: 维修类目
 *         required: true
 *         type: string
 *       - name: price
 *         description: 单项价格
 *         required: true
 *         type: number
 *       - name: total_price
 *         description: 维修总价
 *         required: true
 *         type: number
 *       - name: date
 *         description: 维修周期
 *         required: true
 *         type: date
 *     responses:
 *       200:
 *         description: 返回信息
 *         schema:
 *           type: object
 *           properties:
 *             data:
 *               type: array
 *               default: [
 *                 {
 *                   "message": "修改成功"
 *                 }
 *               ]
 *       401:
 *         description: 参数错误
 */


router.post('/update', async (ctx) => {
    const body = ctx.request.body
    const result = await updatePlanList(body)
    return ctx.result.success(result)
})

module.exports = router